package com.topevery.adminclient.controller;

import com.topevery.adminclient.model.Book;
import com.topevery.adminclient.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@RestController
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping("/")
    public String index(){
        return "Index";
    }

    @GetMapping("/getBookById")
    public Book getBookById(Integer bookId){
        System.out.println("bookId="+ bookId);
        return bookService.getById(bookId);
    }

    @GetMapping("/testMessage")
    public String testMessage(Integer bookId){
        return LocalDateTime.now().toString() + bookId.toString();

    }

    @PostMapping("/createBook")
    public boolean createBook(){
        Book book = new Book();
        book.setName("人类简史");
        book.setPublishDate(LocalDateTime.now());
        book.setSex(true);
        book.setTotalPage(500);

        return bookService.save(book);
    }
}
